package hzau.controller;

import hzau.pojo.requestParams.LoginParams;
import hzau.pojo.requestParams.TeacherRegisterParam;
import hzau.result.Result;
import hzau.service.TeacherService;
import hzau.utils.JwtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@CrossOrigin
@RestController
@RequestMapping("teacher")
@Api(tags = "教师相关接口")
public class TeacherController {
    @Autowired
    TeacherService teacherService;
    @PostMapping("login")
    @ApiOperation("教师登录功能")
    public Result login(@RequestBody LoginParams loginParams){

        return teacherService.login(loginParams);
    }
    @PostMapping("register")
    @ApiOperation("教师注册功能")
    public Result teacherRegister(@RequestBody TeacherRegisterParam teacher){
        return teacherService.register(teacher);
    }
    @DeleteMapping("delete")
    @ApiOperation("教师注销功能")
    public Result delete(Long id){
        return teacherService.delete(id);
    }
    @GetMapping("getOne")
    @ApiOperation("获取一个教师的信息")
    public Result getOne(@RequestHeader("token") String token){
            Long userId = JwtUtils.getUserId(token);
        return teacherService.getOne(userId);
    }
    @GetMapping("getAll/{collegeId}/{pageNum}")
    @ApiOperation("获取一个学院的教师信息")
    public Result getAll(@PathVariable Long collegeId , @PathVariable Integer pageNum){
        return teacherService.getAll(collegeId,pageNum);
    }
    @GetMapping("getAllTeacher/{collegeId}")
    @ApiOperation("获取一个学院的教师信息")
    public Result getAllTeacher(@PathVariable Long collegeId){
        return teacherService.getAllTeacher(collegeId);
    }
    @PostMapping("update")
    @ApiOperation("更新教师信息")
    public Result update(@RequestHeader("token") String token,@RequestBody TeacherRegisterParam teacher){
        Long userId = JwtUtils.getUserId(token);
        return teacherService.update(userId,teacher);
    }
    @GetMapping("getCourseNames")
    @ApiOperation("查询教授课程名称")
    public Result getCourseNames(@RequestHeader("token") String token){

        Long userId = JwtUtils.getUserId(token);
        return teacherService.getCourseNames(userId);
    }
    @GetMapping("getTeacherNames/{courseId}")
    @ApiOperation("根据课程查询授课教师")
    public Result getTeacherNames(@PathVariable Long courseId){

        return teacherService.getTeacherNames(courseId);
    }
    @GetMapping("getTeachersWithoutCourse/{courseId}/{collegeId}")
    @ApiOperation("根据学院查询可授课教师")
    public Result getTeachersWithoutCourse(@PathVariable Long courseId,@PathVariable Long collegeId){

        return teacherService.getTeachersWithoutCourse(courseId,collegeId);
    }
    @GetMapping("getTeachersTeachCourse/{courseId}/{collegeId}")
    @ApiOperation("根据学院查询可出卷教师")
    public Result getTeachersTeachCourse(@PathVariable Long courseId,@PathVariable Long collegeId){

        return teacherService.getTeachersTeachCourse(courseId,collegeId);
    }
    @PostMapping("addTeacherWithoutCourse")
    @ApiOperation("根据学院查询可授课教师")
    public Result addTeacherWithoutCourse( Long courseId, Long teacherId){

        return teacherService.addTeacherWithoutCourse(courseId,teacherId);
    }
    @PostMapping("deleteTeacherWithCourse")
    @ApiOperation("根据学院查询可授课教师")
    public Result deleteTeacherWithCourse( Long courseId, Long teacherId){

        return teacherService.deleteTeacherWithCourse(courseId,teacherId);
    }
    @GetMapping("getCreateTeacher/{courseId}")
    @ApiOperation("根据查询出卷教师")
    public Result getCreateTeacher(@PathVariable Long courseId){

        return teacherService.getCreateTeacher(courseId);
    }
    @GetMapping("getReviewTeacher/{courseId}")
    @ApiOperation("根据查询评审教师")
    public Result getReviewTeacher(@PathVariable Long courseId){

        return teacherService.getReviewTeacher(courseId);
    }
    @GetMapping("getTeachersCourse/{courseId}/{collegeId}")
    @ApiOperation("根据学院查询评审教师")
    public Result getTeachersCourse(@PathVariable Long courseId,@PathVariable Long collegeId){

        return teacherService.getTeachersCourse(courseId,collegeId);
    }


}
